package com.java.demo.string;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.util.StringUtils;

public class DemoString {

	public static String toLowerCase(String param) {
		char[] array = param.toCharArray();
		array[0] += 32;
		return new String(array);
	}

	public static String getIP() {
		String ip = "127.0.0.1:8080";
		return ip.substring(0, ip.indexOf(":"));
	}

	public static void main(String[] args) {
		double d = -10.00002;
		DecimalFormat df = new DecimalFormat("0.00");
		System.out.println(df.format(d));
	}

	public static boolean checkString(String text, String regex) {
		if (StringUtils.isEmpty(text) || StringUtils.isEmpty(regex)) {
			return false;
		}
		Matcher matcher = Pattern.compile(regex).matcher(text);
		return matcher.matches();
	}

	public static void demo() {
		Map<Long, Integer> map = new HashMap<>(16);
		map.put(500L, map.getOrDefault(500L, 0) + 1);
		String str = "ABC123abc";
		boolean flag = str.equalsIgnoreCase("abc123abc");
		System.out.println(flag);
	}
}
